import axios from 'axios';
import store from '../lib/store';
import qs from 'qs';


const Util = {
    imgPath: 'http://127.0.0.1:8011/img',
    apiPath: '/apis/'
};

Util.ajax = axios.create({
    baseURL: Util.apiPath,
    //timeout: 1000,
    //headers: {'Access-Control-Allow-Origin': '*'}
    headers: {
        'Authorization': 'Basic aW1vb2M6aW1vb2NzZWNyZXQ='
    }
});

const _this = this;

Util.ajax.interceptors.request.use(
    config => {
        const token = (store.getters.getStorage);
        if (null != token) {
            config.headers.Authorization = `${token.token_type} ${token.access_token}`
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);


Util.ajax.interceptors.response.use(res => {
    if(res.status==200){
        return res.data;
    }
});

Util.openProcessLoading = function (_this, loadMsg) {
    _this.$Spin.show({
        render: (h) => {
            return h('div', [
                h('Icon', {
                    'class': 'demo-spin-icon-load',
                    props: {
                        type: 'load-a',
                        size: 18
                    }
                }),
                h('div', loadMsg + ',请稍后...')
            ])
        }
    });
};
Util.closeProcessLoading = function (_this) {
    _this.$Spin.hide();
};

export default Util;
